﻿using BUS;
using DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace QLVBDQ
{
    /// <summary>
    /// Interaction logic for TimKiemTho.xaml
    /// </summary>
    public partial class TimKiemTho : UserControl
    {
        public TimKiemTho()
        {
            InitializeComponent();
        }

        private void btnTim_Click(object sender, RoutedEventArgs e)
        {
            if (this.maTho.Text =="" && this.tenTho.Text=="" && this.diaChi.Text=="")
            {
                MessageBox.Show("Phải nhập ít nhất 1 thông tin!");
                this.listTho.Items.Clear();
                return;
            }
            Tho_DTO input = new Tho_DTO(this.maTho.Text.ToString(), this.tenTho.Text.ToString(), this.diaChi.Text.ToString());
            ShowResult(input);
        }

        private void ShowResult(Tho_DTO _tho)
        {
            List<Tho_DTO> list = Tho_BUS.Instance.TimKiemTho(_tho);
            if (list.Count == 0)
            {
                MessageBox.Show("Không tìm thấy thông tin thợ cần tìm!");
                this.listTho.Items.Clear();
                return;
            }
            this.listTho.Items.Clear();
            for (int i = 0; i < list.Count;i++ )
            {
                list[i].STT = i + 1;
                this.listTho.Items.Add(list[i]);
            }
            this.listTho.Items.Refresh();
        }

        

    }
}
